import requests
from common.ihrm_login_get_token import get_req_header

class IhrmEmpApi:
    # 添加员工
    @staticmethod   # 因为方法中没有用到self属性或self方法，所以用静态方法
    def emp_add(req_header, req_body):
        resp = requests.post(url="http://ihrm2-test.itheima.net/api/sys/user",
                             headers=req_header,
                             json=req_body)
        return resp

    # 查询员工
    @staticmethod
    def emp_querry(req_id, req_headers):
        resp = requests.get(url="http://ihrm2-test.itheima.net/api/sys/user/" + req_id,
                            headers=req_headers)
        return resp

    # 修改员工
    @staticmethod
    def emp_modify(req_id, req_headers, req_data):
        resp = requests.put(url="http://ihrm2-test.itheima.net/api/sys/user/"+ req_id,
                            headers=req_headers,
                            json=req_data)
        return resp

    # 删除员工
    @staticmethod
    def emp_delete(req_id, req_headers):
        resp = requests.delete(url="http://ihrm2-test.itheima.net/api/sys/user/"+req_id,
                               headers=req_headers)
        return resp

# 自测
if __name__ =="__main__":
    req_header = get_req_header()
    req_body = {"username": "user2", "mobile": "13947884781", "workNumber": "9527890aa"}
    res = IhrmEmpApi.emp_add(req_header, req_body)
    print(res)
